﻿Public Class frmComptage
    Private szSQL As String
    Private rs As ADODB.Recordset = Nothing

    Private Sub frmComptage_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        CB_TYPE.SelectedIndex = 0

    End Sub

    Private Sub CB_TYPE_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles CB_TYPE.SelectedIndexChanged

        Dim nb As Integer = 0
        Dim nbDossiers As Integer = 0

        ' effacer la listview
        LV_COMPTEURS.Items.Clear()

        If CB_TYPE.SelectedItem = "CLIENTS" Then
            szSQL = "SELECT COALESCE(year(dern_operation),'') as year,count(*) as nb FROM " & CB_TYPE.SelectedItem & _
                    " WHERE societe='" & gSocieteCode & "' GROUP BY year(dern_operation);"
        Else
            szSQL = "SELECT COALESCE(year(date),'') as year,count(*) as nb FROM " & CB_TYPE.SelectedItem & _
                    " WHERE societe='" & gSocieteCode & "' GROUP BY year(date);"
        End If
        GetRecordset(ctDSN_DEVFAC, szSQL, rs)

        ' Load the data.
        nbDossiers = 0
        Do While Not rs.EOF
            LV_COMPTEURS.Items.Add(rs.Fields("year").Value)
            LV_COMPTEURS.Items(nb).SubItems.Add(rs.Fields("nb").Value)
            nb += 1
            nbDossiers += rs.Fields("nb").Value
            ' Get the next record
            rs.MoveNext()
        Loop
        ' Close the recordset AND connection.
        rs.Close()
        TE_TOTAL.Text = nbDossiers

    End Sub

End Class